package discard.kv;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;


import hyl.core.conf.MyConfig;

/**
 * 缓冲池
 * 
 * 运行阶段的所有缓存 都放在池子里
 * 
 * 统一管理
 * 
 * @author 37798955@qq.com
 *
 */
public class ConfigPool {
	public Map<String, ConfigCache> cofs = new HashMap<>();
	public Map<String, ConfigKvCache> ehcofs = new HashMap<>();
	private static ConfigPool cp;

	public static ConfigPool getInstance() {
		if (cp == null)
			cp = new ConfigPool();
		return cp;
	}

	public ConfigPool() {
		Map<String, Map<String, String>> confs = MyConfig.getConfOfCache();
		if (confs == null)
			return;
		// System.out.println(JSON.toJSONString(confs));
		for (Entry<String, Map<String, String>> s : confs.entrySet()) {
			Map<String, String> conf = s.getValue();
			// 加载自定义 cache配置
			cofs.put(s.getKey(), new ConfigCache(conf));

			// 如果有这个配置项那么 追加 ehcache 配置
			if (conf.containsKey("dir"))
				ehcofs.put(s.getKey(), new ConfigKvCache(conf));
		}
	}

	public ConfigCache getCacheConfig(String alias) {
		return cofs.get(alias);
	}

	public ConfigKvCache getKvCacheConfig(String alias) {
		return ehcofs.get(alias);
	}
	
}
